﻿using project.B12.IRepository;
using project.B12.IRepository.Base;
using project.B12.Model.Models;
using project.B12.Repository.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace project.B12.Repository
{
    public class RunningRepository:SugarRepository<Table_MonitorMes>,IMonitorMesRepository
    {
        private IUnitOfWork UOW;

        public RunningRepository(IUnitOfWork pUOW):base(pUOW) 
        {
            UOW = pUOW;
        }

        public List<Table_MonitorMes> QueryAllMonitorMes()
        {
            List<Table_MonitorMes> retsult;
            try
            {
                UOW.BeginTran();
                retsult = Query().Result;
                UOW.CommitTran();
            }
            catch(Exception ex)
            {
                UOW.RollbackTran();
                throw ex;
            }
            return retsult;
        }

        public void UpdateMonitorMes(Table_MonitorMes model)
        {
            try
            {
                UOW.BeginTran();
                Update(model);
                UOW.CommitTran();
            }
            catch (Exception ex)
            {
                UOW.RollbackTran();
                throw ex;
            }
        }

        public void AddMonitorMes(Table_MonitorMes model)
        {
            try
            {
                UOW.BeginTran();
                var result= Add(model);
                model.Id = result.Result;
                UOW.CommitTran();
            }
            catch (Exception ex)
            {
                UOW.RollbackTran();
                throw ex;
            }
        }

        public void DeleteMonitorMes(Table_MonitorMes model)
        {
            try
            {
                UOW.BeginTran();
                Delete(model);
                UOW.CommitTran();
            }
            catch (Exception ex)
            {
                UOW.RollbackTran();
                throw ex;
            }
        }
    }
}
